<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">留言</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>

			<view class="top-line"></view>
			<view style="width: 350px;">
				<uni-forms ref="baseForm" :modelValue="baseFormData">
					<uni-forms-item label="留言内容：" labelAlign="right">
					<uni-easyinput type="textarea" v-model="baseFormData.content" placeholder="请输入留言内容" />
					</uni-forms-item>
					<uni-forms-item label="姓名:" labelAlign="right">
						<uni-easyinput v-model="baseFormData.userName" placeholder="请输入姓名" />
					</uni-forms-item>
					<uni-forms-item label="联系电话:" labelAlign="right">
						<uni-easyinput v-model="baseFormData.userMobile" placeholder="请输入电话" />
					</uni-forms-item>
					
				</uni-forms>
			</view>
			<view class="bottom-back">
				<view class="bottom-btn bottom-btn-cancel">取消</view>
				<view class="bottom-btn" @click="saveAction">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseFormData: {
					'userName': '',
					'userMobile':'',
					'content':''
					
				}
			}
		},
		mounted() {
			var phone = getApp().globalData.userInfo.mobile;
			 if(phone){
				 this.$set(this.baseFormData, 'userMobile', phone)			 
			 }
		},
		methods: {
			async saveAction() {
				let _this = this
				var re = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
				if (!/^1[3456789]\d{9}$/.test(this.baseFormData.userMobile)) {
				   uni.showToast({
				      title: '请输入正确的手机号',
				      icon: 'none'
				        });
				     return false;
				 }
				
			
				var parms = {
					'userName': this.baseFormData.userName,
					'userMobile': this.baseFormData.userMobile,
					'content': this.baseFormData.content,
				}
				const res = await this.$myRequest({
					url: "/client/leaveMsg",
					method: 'POST',
					data: parms
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					uni.showToast({
						title: '留言成功'
					})
					
					_this.closeBtnAction()
				}
			},
			closeBtnAction() {
				this.$emit('leaveMessageClose')
			},
			moveHandle() {
				return true
			},
		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 299;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 552px;
		height: 500px;
		padding: 24px;
		max-height: 500px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {

		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bottom-btn-cancel {
		margin-right: 10px;
		background: #FFFFFF;
		border: 1px solid #EEEEEE;
		color: #333333;
	}
</style>
